<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>上传数据--Instreet</title>
    <%include ../head%>
    <link rel="stylesheet" type="text/css" href="/css/datepicker.css">  
  </head>
  <body>
      <%include ../header%>
      <div id="container">
        <div class="container">
          <h4 class="edit-form-top">
            <span>导出数据(<%=title%>)</span>
          </h4>
          <form class="form-horizontal">
            <input type="hidden" id="field" name="field" value="<%=field%>"> 
            <input type="hidden" id="title" name="title"  value="<%=title%>"/>
            <div class="row">
              <div class="span6">
                <div class="control-group">
                  <label class="control-label">选择日期：</label >
                  <div class="controls">
                    <div class="input-daterange">
                        <input id="date_from" name="date_from" class="datepicker input-small" maxlength="10" type="text" value="<%=from%>"/>
                        <span class="add-on">至</span>
                        <input id="date_to" name="date_to" class="datepicker input-small" maxlength="10" type="text" value="<%=to%>">  
                    </div>     
                  </div>           
                </div>
              </div>
              <div class="span2">           
               <button type="submit" style="vertical-align:top;" href="javascript:;" class="btn btn-primary btn_search">查询</button>    
              </div>      
            </div> 
          </form>

          <div>
          <%if(typeof reportData!='undefined'&&reportData.length){%>

            <table class="table table-bordered table-striped">
              <thead>
                <th>日期</th>
                <th>请求次数</th>
                <th>曝光次数</th>
                <th>点击次数</th>
                <th>收入(人民币)</th>
                <th><a href="javascript:;" class="btn btn-info btn-export">导出Excel</a></th>
              </thead>
              <tbody>
                <%var exelData = [];reportData.forEach(function(data,i){
                  if(data!=null){  
                    data = JSON.parse(data);
                    exelData.push([data.date,data.request,data.view,data.click,parseFloat(data.revenue)]);

                  %>
                  <tr><td><%=data.date%></td><td><%=data.request%></td><td><%=data.view%></td><td><%=data.click%></td><td><%=data.revenue%></td><td></td></tr>
                <%}});%>              
              </tbody>
            </table>
            <form id="form-excel" method="POST">
             <input type="hidden" name="reportData" value = '<%-JSON.stringify(exelData)%>'>
            </form>
            <%}%>
          </div>


        </div>
      </div>
      <%include ../script%>
      <script type="text/javascript" >        
        seajs.use(['/js/main','datepicker'],function() {
          var d = new Date();
          var field = $('#field').val()
              ,title = $('#title').val()
              ;
          var dateOpt = { 
            autoclose:true,
            language : 'zh-CN',     
            format : 'yyyy-mm-dd',
            weekStart : 1,
            todayHighlight:true,            
            endDate : [d.getFullYear(),d.getMonth()+1,d.getDate()].join('-')
          }
          // 初始化日历插件
          $('.input-daterange').datepicker(dateOpt);  
          // 导出数据为excel
          $('.btn-export').on('click',function() {
            $('#form-excel').submit();
          })

        });
      </script>
      <%include ../footer%>
 </body>
 </html>